package com.itstudio.portal.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itstudio.portal.entity.Project;
import com.itstudio.portal.entity.RestResponse;
import com.itstudio.portal.entity.dto.ProjectAddDto;
import com.itstudio.portal.entity.dto.ProjectDto;
import com.itstudio.portal.mapper.ProjectMapper;
import com.itstudio.portal.service.ProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/api/project")
public class ProjectController {
    @Autowired
     ProjectService projectService;

    @Autowired
    private ProjectMapper projectMapper;
    //查看个人项目
    @GetMapping("/myselfProject")
    public RestResponse selectMyProject(HttpServletRequest request){
        return projectService.selectMyProject(request);
    }
    //项目发布
    @PostMapping("/add")
    public RestResponse add(@RequestBody ProjectAddDto projectAddDto, HttpServletRequest request){
        return projectService.add(projectAddDto, request);
    }
    //项目删除
    @DeleteMapping("/delete/{id}")
    public RestResponse delete(@PathVariable Long id){
        return projectService.delete(id);
    }


    //项目修改
    @PutMapping("/update")
    public RestResponse updateProject (@RequestBody ProjectAddDto projectAddDto,HttpServletRequest request){
        return projectService.updateProject(projectAddDto,request);
    }


    //项目查询
    @PostMapping("/list")
    public RestResponse getList(@RequestBody ProjectDto projectDto) {
        return projectService.getList(projectDto);
    }


    //根据id查看具体的详情
    @GetMapping("/{id}")
    public RestResponse getProjectById(@PathVariable Long id){
        return projectService.getProjectById(id);
    }

    //更新浏览量
    @PutMapping("/updateView/{id}")
    public RestResponse updateView(@PathVariable Long id){
        return projectService.updateView(id);
    }

}
